﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Pevolution
{
    class Input
    {
        private static KeyboardState keyboard = Keyboard.GetState();
        private static KeyboardState oldKeyboard;
        private static MouseState mouse = Mouse.GetState();
        private static MouseState oldMouse;

        #region Keyboard
        public bool isKeyDown(Keys key)
        {
            if (keyboard.IsKeyDown(key))
                return true;
            else
                return false;
        }

        public bool isKeyUp(Keys key)
        {
            if (keyboard.IsKeyDown(key))
                return false;
            else
                return true;
        }

        public bool isKeyPressed(Keys key)
        {
            if (keyboard.IsKeyDown(key) && oldKeyboard.IsKeyUp(key))
            {
                return false;
            }
            else
            {
                return false;
            }
        }

        #endregion

        #region Mouse
        #region MouseDown
        public bool isLeftMouseButtonDown()
        {
            if (mouse.LeftButton == ButtonState.Pressed)
                return true;
            else
                return false;
        }

        public bool isRightMouseButtonDown()
        {
            if (mouse.RightButton == ButtonState.Pressed)
                return true;
            else
                return false;
        }

        public bool isMiddleMouseButtonDown()
        {
            if (mouse.MiddleButton == ButtonState.Pressed)
                return true;
            else
                return false;
        }
        #endregion

        #region MouseUp
        public bool isLeftMouseButtonUp()
        {
            if (mouse.LeftButton == ButtonState.Pressed)
                return false;
            else
                return false;
        }

        public bool isRightMouseButtonUp()
        {
            if (mouse.RightButton == ButtonState.Pressed)
                return false;
            else
                return true;
        }

        public bool isMiddleMouseButtonUp()
        {
            if (mouse.MiddleButton == ButtonState.Pressed)
                return false;
            else
                return true;
        }
        #endregion

        #region MouseClicked
        public bool isLeftMouseButtonClicked()
        {
            if (mouse.LeftButton == ButtonState.Pressed && oldMouse.LeftButton == ButtonState.Released)
                return true;
            else
                return false;
        }

        public bool isRightMouseButtonClicked()
        {
            if (mouse.RightButton == ButtonState.Pressed && oldMouse.RightButton == ButtonState.Released)
                return true;
            else
                return false;
        }

        public bool isMiddleMouseButtonClicked()
        {
            if (mouse.MiddleButton == ButtonState.Pressed && oldMouse.MiddleButton == ButtonState.Released)
                return true;
            else
                return false;
        }
        #endregion
        #endregion

        public Vector2 getMousePosition()
        {
            return new Vector2(mouse.X, mouse.Y);
        }
    }
}
